import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/app/theme/gaps.dart';
import 'package:bxultimate/widgets/app/app_input.dart';
import 'package:bxultimate/widgets/app/app_title.dart';
import 'package:bxultimate/widgets/app/app_upload.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:bxultimate/widgets/mk_scroll_view.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart' hide TDInput, TDInputType;

import 'controller.dart';

class PublishIntellPage extends StatefulWidget {
  const PublishIntellPage({Key? key}) : super(key: key);

  @override
  State<PublishIntellPage> createState() => _PublishIntellPageState();
}

class _PublishIntellPageState extends State<PublishIntellPage> {
  final controller = Get.find<PublishIntellController>();
  final state = Get.find<PublishIntellController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: TDNavBar(
          backgroundColor: Colors.transparent,
          title: '发布情报',
        ),
        body: MkScrollView(
          bottomButton: TDButton(
            text: '确认上报',
            shape: TDButtonShape.circle,
            height: 48,
            onTap: controller.publish,
            isBlock: true,
            theme: TDButtonTheme.primary,
          ),
          children: [
            Gaps.vGap16,
            Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppTitle(title: '请填写基本信息')),
            Gaps.vGap16,
            TDInput(
              controller: controller.typeController,
              leftLabel: '类型',
              required: true,
              readOnly: true,
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
            ),
            Obx(() => TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: state.addressName != ''
                      ? _noteWidget('')
                      : _noteWidget('请选择地理位置'),
                  description: state.addressName == '' ? '' : state.addressName,
                  title: '地理位置',
                  onClick: controller.addressSelect,
                )),
            Obx(() => TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: state.upUnit == ''
                      ? _noteWidget('请选择上报单位')
                      : _noteWidget(state.upUnit!),
                  title: '上报单位',
                  onClick: controller.showUpUnitSelect,
                )),
            TDInput(
              controller: controller.phoneController,
              required: true,
              maxLength: 11,
              leftLabel: '手机号',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
              hintText: '请输入手机号',
              inputType: TextInputType.phone,
            ),

            Obx(() => TDCell(
                  style: TDCellStyle(
                      backgroundColor: Colors.transparent,
                      requiredStyle: TextStyle(
                        color: TDTheme.of(context).errorColor6,
                        fontSize: TDTheme.of(context).fontBodyLarge?.size ?? 16,
                        height: TDTheme.of(context).fontBodyLarge?.height ?? 24,
                        fontWeight: FontWeight.w400,
                      )),
                  arrow: true,
                  required: true,
                  noteWidget: state.upTime == ''
                      ? _noteWidget('请选择时间')
                      : _noteWidget(state.upTime),
                  title: '上报时间',
                  onClick: controller.showUpTimeSelect,
                )),

            TDInput(
              controller: controller.detailController,
              maxLength: 200,
              leftLabel: '详情',
              type: TDInputType.special,
              textAlign: TextAlign.end,
              backgroundColor: Colors.transparent,
              hintText: '请输入详细信息',
              inputType: TextInputType.phone,
            ),

            // 上传图片或者商品
            Padding(
              padding: EdgeInsets.all(AppTheme.iDefaultPadding + 4),
              child: Row(
                children: [
                  Text(
                    '添加图片/视频',
                    style: TextStyle(fontSize: 16),
                  ),
                ],
              ),
            ),
            Obx(() => Padding(
                padding: EdgeInsets.only(left: AppTheme.iDefaultPadding),
                child: AppUpload(
                  imgList: state.imgList,
                  videoList: state.videoList,
                )))
          ],
        ),
      ),
    );
  }

  _noteWidget(text) {
    return Text(
      text,
      style: TextStyle(fontSize: 16),
    );
  }

  @override
  void dispose() {
    Get.delete<PublishIntellController>();
    super.dispose();
  }
}
